function e(e) {
    var a = {
        province: "",
        city: "",
        area: "",
        addr: "",
        name: ""
    }, r = [ "特别行政区", "古自治区", "维吾尔自治区", "壮族自治区", "回族自治区", "自治区", "省省直辖", "省", "市" ], n = [ "布依族苗族自治州", "苗族侗族自治州", "自治州", "州", "市", "县" ];
    for (var i in d) {
        var t = d[i], c = e.indexOf(t.name);
        if (c > -1) {
            c > 0 && (a.name = e.substr(0, c).trim()), a.province = t.name, e = e.substr(c + t.name.length);
            for (var f in r) 0 === e.indexOf(r[f]) && (e = e.substr(r[f].length));
            for (var s in t.city) {
                var l = t.city[s];
                if ((c = e.indexOf(l.name)) > -1 && c < 3) {
                    a.city = l.name, e = e.substr(c + a.city.length);
                    for (var o in n) 0 === e.indexOf(n[o]) && (e = e.substr(n[o].length));
                    if (l.area) for (var p in l.area) {
                        var u = l.area[p];
                        if ((c = e.indexOf(u)) > -1 && c < 3) {
                            a.area = u, e = e.substr(c + a.area.length);
                            break;
                        }
                    }
                    break;
                }
            }
            a.addr = e.trim();
            break;
        }
    }
    return a;
}

function a(e) {
    var a = (arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}).ignoreArea, r = void 0 !== a && a, n = {
        province: "",
        city: "",
        area: "",
        name: "",
        _area: "",
        addr: ""
    }, i = -1, t = -1;
    if (e = e.replace("  ", " "), !r && e.indexOf("县") > -1 || !r && e.indexOf("区") > -1 || !r && e.indexOf("旗") > -1) e.indexOf("旗") > -1 && (i = e.indexOf("旗"), 
    n.area = e.substr(i - 1, 2)), e.indexOf("区") > -1 && (i = e.indexOf("区"), e.lastIndexOf("市", i) > -1 ? (t = e.lastIndexOf("市", i), 
    n.area = e.substr(t + 1, i - t)) : n.area = e.substr(i - 2, 3)), e.indexOf("县") > -1 && (i = e.lastIndexOf("县"), 
    e.lastIndexOf("市", i) > -1 ? (t = e.lastIndexOf("市", i), n.area = e.substr(t + 1, i - t)) : n.area = e.substr(i - 2, 3)), 
    n.addr = e.substr(i + 1); else if (e.indexOf("市") > -1) if (i = e.indexOf("市"), 
    console.log(e.split(" ")), e.split(" ")[0].indexOf("市") > -1) {
        var d = e.split(" ")[0].indexOf("市");
        n.area = e.split(" ")[0].substr(0, d + 1), n.addr = e.split(" ")[0].substr(d + 1), 
        n.name = e.split(" ")[1];
    } else {
        var s = e.split(" ")[1].indexOf("市");
        n.area = e.split(" ")[1].substr(0, s + 1), n.addr = e.split(" ")[1].substr(s + 1), 
        n.name = e.split(" ")[0];
    } else n.addr = e;
    if ((e.indexOf("市") > -1 || e.indexOf("盟") > -1 || e.indexOf("州") > -1) && (e.indexOf("市") > -1 && (n._area = e.substr(e.indexOf("市") - 2, 2)), 
    e.indexOf("盟") > -1 && !c[n._area] && (n._area = e.substr(e.indexOf("盟") - 2, 2)), 
    e.indexOf("州") > -1 && !c[n._area] && (n._area = e.substr(e.indexOf("州") - 2, 2))), 
    n.area = n.area.trim(), n.area && f[n.area]) if (1 === f[n.area].length) n.province = f[n.area][0].p, 
    n.city = f[n.area][0].c; else {
        n._area = n._area.trim();
        var l = e.substr(0, i), o = f[n.area].find(function(e) {
            return e.p.indexOf(l) > -1 || e.c === n._area;
        });
        o ? (n.province = o.p, n.city = o.c) : n.result = f[n.area];
    } else if (n._area) {
        var p = c[n._area];
        if (p) {
            n.province = p[0].p, n.city = p[0].c, n.addr = e.substr(e.indexOf(n.city) + n.city.length + 1), 
            n.area = "";
            for (var u in p[0].a) if (0 === n.addr.indexOf(p[0].a[u])) {
                n.area = p[0].a[u], n.addr = n.addr.replace(p[0].a[u], "");
                break;
            }
        }
    } else n.area = "";
    return n.addr = n.addr.trim(), n;
}

var r = require("./area-list.js"), n = r.zipCode, i = r.areaList, t = r.foramtProvince, d = [], c = {}, f = {}, s = function() {
    var e = [];
    return n.forEach(function(a) {
        a.child && a.child.forEach(function(a) {
            a.child && a.child.forEach(function(a) {
                e.push(a.zipcode);
            });
        });
    }), e;
}();

!function(e, a) {
    if (!a && d.length) return !0;
    (d = e).forEach(function(e) {
        e.city && e.city.forEach(function(a) {
            "其他" !== a.name && (c[a.name] || (c[a.name] = []), c[a.name].push({
                p: e.name,
                c: a.name,
                a: a.area || []
            })), a.area && a.area.forEach(function(r) {
                "其他" !== r && (f[r] || (f[r] = []), f[r].push({
                    p: e.name,
                    c: a.name
                }));
            });
        });
    });
}(i), module.exports = function(r) {
    r = r || "";
    var i = {
        name: "",
        mobile: "",
        detail: "",
        zip_code: "",
        phone: ""
    };
    [ "地址", "收货地址", "收货人", "收件人", "收货", "邮编", "电话", "：", ":", "；", ";", "，", ",", "。", " " ].forEach(function(e) {
        r = r.replace(new RegExp(e, "g"), " ");
    }), r = r.replace(/ {2,}/g, " "), r = r.replace(/(\d{3})-(\d{4})-(\d{4})/g, "$1$2$3"), 
    r = r.replace(/(\d{3}) (\d{4}) (\d{4})/g, "$1$2$3");
    var d = /(86-[1][0-9]{10})|(86[1][0-9]{10})|([1][0-9]{10})/g.exec(r);
    d && (i.mobile = d[0], r = r.replace(d[0], " "));
    var c = /(([0-9]{3,4}-)[0-9]{7,8})|([0-9]{12})|([0-9]{11})|([0-9]{10})|([0-9]{9})|([0-9]{8})|([0-9]{7})/g.exec(r);
    c && (i.phone = c[0], r = r.replace(c[0], " "));
    for (var f = 0; f < s.length; f++) if (-1 != r.indexOf(s[f])) {
        var l = r.indexOf(s[f]), o = r.slice(l, l + 6);
        i.zip_code = o, r = r.replace(o, "");
    }
    var p = e((r = r.replace(/ {2,}/, " ")).trim()), u = p.province;
    if (p.city) if (p.name) i.name = p.name; else {
        var m = p.addr.split(" ").filter(function(e) {
            return e;
        });
        m.length > 1 && (i.name = m[m.length - 1]), i.name && (p.addr = p.addr.replace(i.name, "").trim());
    } else {
        (p = a(r.trim())).area && !p.city && (p = a(r.trim(), {
            ignoreArea: !0
        }), console.log("smart_parse->ignoreArea（忽略区）"));
        var v = r.replace(p.province, "").replace(p.city, "").replace(p.area, "").split(" ").filter(function(e) {
            return e;
        }), x = [ "室", "楼", "元", "号", "幢", "门", "户" ];
        if (v.length > 1) v.forEach(function(e) {
            (!i.name || e && e.length < i.name.length) && (i.name = e.trim());
        }), i.name && (p.addr = p.addr.replace(i.name, "").trim()); else {
            var O = [];
            x.forEach(function(e) {
                O.push(p.addr.indexOf(e));
            });
            var h = O.sort(function(e, a) {
                return a - e;
            })[0];
            if (p.name && (i.name = p.name), -1 != h) {
                var g = p.addr.slice(0, h + 1), b = p.addr.replace(g, "").replace(/[^0-9]+/g, ""), y = p.addr.replace(g + b, "");
                p.addr = g + b, i.name = y;
            }
        }
    }
    return i.province = "" == p.province ? u : p.province, i.city = p.city, i.area = p.area, 
    i.addr = p.addr, i.result = p.result, t.forEach(function(e) {
        0 == e.name.indexOf(i.province) && (i.province = e.name);
    }), n.forEach(function(e) {
        0 == i.province.indexOf(e.name) && e.child.forEach(function(e) {
            0 == e.name.indexOf(i.city) && (i.city = e.name);
        });
    }), i;
};